package cn.lili.controller.statistics;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.order.aftersale.entity.dos.AfterSale;
import cn.lili.modules.order.order.client.AfterSaleStatisticsClient;
import cn.lili.modules.order.order.client.OrderStatisticsClient;
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
import cn.lili.modules.statistics.entity.dto.OrderPromotionStatisticsQueryParam;
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
import cn.lili.modules.statistics.entity.vo.OrderOverviewVO;
import cn.lili.modules.statistics.entity.vo.OrderStatisticsDataVO;
import cn.lili.modules.statistics.service.StatisticsCombineService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单统计接口
 *
 * @author Bulbasaur
 * @since 2020/12/9 19:04
 */
@Slf4j
@Api(tags = "订单统计接口")
@RestController
@RequestMapping("/statistics/order")
@RequiredArgsConstructor
public class OrderStatisticsController {

    private final OrderStatisticsClient orderStatisticsClient;

    private final AfterSaleStatisticsClient afterSaleStatisticsClient;


    private final StatisticsCombineService statisticsCombineService;

    @ApiOperation(value = "订单概览统计")
    @GetMapping("/overview")
    public ResultMessage<OrderOverviewVO> overview(StatisticsQueryParam statisticsQueryParam) {
        try {
            return ResultUtil.data(statisticsCombineService.overview(statisticsQueryParam));
        } catch (Exception e) {
            log.error("订单概览统计错误", e);
        }
        return null;
    }

    @ApiOperation(value = "订单图表统计")
    @GetMapping
    public ResultMessage<List<OrderStatisticsDataVO>> statisticsChart(StatisticsQueryParam statisticsQueryParam) {
        try {
            return ResultUtil.data(orderStatisticsClient.statisticsChart(statisticsQueryParam));
        } catch (Exception e) {
            log.error("订单图表统计", e);
        }
        return null;
    }


    @ApiOperation(value = "订单统计")
    @GetMapping("/order")
    public ResultMessage<Page<OrderSimpleVO>> order(StatisticsQueryParam statisticsQueryParam) {
        try {
            return ResultUtil.data(orderStatisticsClient.getStatistics(statisticsQueryParam));
        } catch (Exception e) {
            log.error("订单统计", e);
        }
        return null;
    }


    @ApiOperation(value = "退单统计")
    @GetMapping("/refund")
    public ResultMessage<Page<AfterSale>> refund(StatisticsQueryParam statisticsQueryParam) {
        return ResultUtil.data(afterSaleStatisticsClient.getStatistics(statisticsQueryParam));
    }

    @ApiOperation(value = "活动订单统计")
    @GetMapping("/promotion")
    public ResultMessage<Page<OrderSimpleVO>> promotion(OrderPromotionStatisticsQueryParam statisticsQueryParam) {
        return ResultUtil.data(orderStatisticsClient.getOrderPromotionStatistics(statisticsQueryParam));
    }
}
